package com.cmcc.groupcontacts.firewall.activity;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TabHost;
import android.widget.TextView;

import com.yinhai.activity.R;


/**
 * 防打扰Tab主界面
 * 
 * @author
 * 
 */
public class FirewallTabActivity extends BaseTabActivity {
	public static final String TAB_INDEX = "TabIndex";

	private TabHost tabHost;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.firewall_tab_activity);

		tabHost = getTabHost();
		tabHost.addTab(tabHost
				.newTabSpec("SmsList")
				.setIndicator(
						createIndicator(R.string.sms_list,
								R.drawable.ic_tab_sms))
				.setContent(new Intent(this, SmsListActivity.class)));
		tabHost.addTab(tabHost
				.newTabSpec("CallList")
				.setIndicator(
						createIndicator(R.string.call_list,
								R.drawable.ic_tab_call))
				.setContent(new Intent(this, CallListActivity.class)));
		tabHost.addTab(tabHost
				.newTabSpec("FilterList")
				.setIndicator(
						createIndicator(R.string.filter_list,
								R.drawable.ic_tab_filter))
				.setContent(new Intent(this, FilterListActivity.class)));
		tabHost.addTab(tabHost
				.newTabSpec("Config")
				.setIndicator(
						createIndicator(R.string.config,
								R.drawable.ic_tab_config))
				.setContent(new Intent(this, FirewallConfigActivity.class)));
	}

	private View createIndicator(int txtResId, int imgResId) {
		View indicator = getLayoutInflater().inflate(
				R.layout.firewall_tab_indicator, null);
		((TextView) indicator.findViewById(R.id.txt_indicator))
				.setText(txtResId);
		((ImageView) indicator.findViewById(R.id.img_indicator))
				.setImageResource(imgResId);
		return indicator;
	}

	@Override
	protected void onResume() {
		super.onResume();

		int currentIndex = getIntent().getIntExtra(TAB_INDEX, -1);
		if (currentIndex >= 0) {
			tabHost.setCurrentTab(currentIndex);
		}

		// TODO: [优化]标识未读的拦截来电和信息
	}

	@Override
	protected void onNewIntent(Intent intent) {
		super.onNewIntent(intent);

		setIntent(intent);
	}
}
